package com.example.demo;

import com.example.demo.dao.EmpDao;
import com.example.demo.dao.StudentDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;

import javax.sql.DataSource;

@SpringBootApplication
@Slf4j
public class DemoApplication implements CommandLineRunner {

	@Autowired
	EmpDao empDao;

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	@Bean
	public NamedParameterJdbcTemplate namedParameterJdbcTemplate(DataSource dataSource){
		return new NamedParameterJdbcTemplate(dataSource);
	}

	@Bean
	public SimpleJdbcInsert simpleJdbcInsert(DataSource dataSource){
		return new SimpleJdbcInsert(dataSource).withTableName("t_emp").usingGeneratedKeyColumns("id");
	}
	@Override
	public void run(String... args) throws Exception {
		empDao.save();
		empDao.saveToId();
		empDao.saveToId2();
		empDao.batch01();
		empDao.batch02();
		empDao.batch03();
		empDao.findAll();
//		empDao.findEmp();
//		empDao.findEmp2();
	}



}
